// 设置文件
// 插件
// import demoPlugins from '@/menu/modules/demo-plugins'
// 组件
// import demoComponents from '@/menu/modules/demo-components'
// 功能
// import demoPlayground from '@/menu/modules/demo-playground'
// 功能列表
import functionlist from '@/menu/modules/functionlist'

// import functionlistrouter from '@/router/modules/functionlist'

// import router from '@/router'

// import { frameInRoutes } from '@/router/routes'
import store from '@/store/index'
import { uniqueId } from 'lodash'

/**
 * @description 给菜单数据补充上 path 字段
 * @description https://github.com/d2-projects/d2-admin/issues/209
 * @param {Array} menu 原始的菜单数据
 */
 function supplementPath (menu) {
  return menu.map(e => ({
    ...e,
    path: e.path || uniqueId('d2-menu-empty-'),
    ...e.children ? {
      children: supplementPath(e.children)
    } : {}
  }))
}

export default {
  namespaced: true,
  state: {
    // 顶栏菜单
    menuHeader: [
        {
          path: '/index',
          title: '首页',
          icon: 'home'
        },
        // functionlist,
        // demoPlayground,
        // demoPlugins
    ],
    // 侧栏菜单
    menuAside: [
        // functionlist,
        // demoPlugins,
        // demoPlayground
    ]
  },
  actions: {
    initial ({ state }){
      state.menuHeader = [{
       path: '/index',
       title: '首页',
       icon: 'home'
     }]
   },
    /**
     * @description 设置顶栏菜单
     * @param {Object} state state
     * @param {Array} menu menu setting
     */
     changeheaderSet ({ state, dispatch }) {
      // 初始设置菜单头和侧边栏都为默认值，防止出现重复菜单
      state.menuHeader = [{
        path: '/index',
        title: '首页',
        icon: 'home'
      }]
      state.menuAside = []
      // store 赋值
      // const route = [functionlistrouter]
      // router.addRoutes(route)
      // console.log(router.getRoutes())
      // router.onReady(()=>{
        
      // })
      // console.log(router)
        // 更新标签页池
        // pageInit([
        //   ...frameInRoutes,
        //   ...route
        // ])
        // store.commit('d2admin/page/init',
        // [
        //   ...frameInRoutes,
        //   ...route
        // ])
        state.menuHeader.push(functionlist)
        state.menuAside.push(functionlist)
        store.commit('d2admin/menu/headerSet',supplementPath(state.menuHeader))
        store.commit('d2admin/menu/asideSet',supplementPath(state.menuAside))
    }
  },
  mutations: {
    // changeasideSet (state, menu) {
    //   // store 赋值
    //   const route = [functionlistrouter]
    //   router.addRoutes(route)
    //   // 更新标签页池
    //   // pageInit([
    //   //   ...frameInRoutes,
    //   //   ...route
    //   // ])
    //   store.commit('d2admin/page/init',
    //   [
    //     ...frameInRoutes,
    //     ...route
    //   ])
    //   state.menuHeader.push(functionlist)
    //   state.menuAside.push(functionlist)
    //   store.commit('d2admin/menu/headerSet',supplementPath(state.menuHeader))
    //   store.commit('d2admin/menu/asideSet',supplementPath(state.menuAside))
    // }
  }
}
